<?php 
 include_once dirname(__FILE__)."/config.php";
 class enseignant_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_cin;
		 protected $_nom_enseig;
		 protected $_prenom_enseig;
		 protected $_tel_mobile;
		 protected $_tel;
		 protected $_fax;
		 protected $_mail;
		 protected $_grade;
		 protected $_specialite;
		 protected $_code_universite;
		 protected $_code_etablissement;
		 protected $_login;
		 protected $_motpasse;
		 public function get_name_table(){ return "enseignant";}
		 public function get_name_cin(){ return "cin";}
		 public function get_name_nom_enseig(){ return "nom_enseig";}
		 public function get_name_prenom_enseig(){ return "prenom_enseig";}
		 public function get_name_tel_mobile(){ return "tel_mobile";}
		 public function get_name_tel(){ return "tel";}
		 public function get_name_fax(){ return "fax";}
		 public function get_name_mail(){ return "mail";}
		 public function get_name_grade(){ return "grade";}
		 public function get_name_specialite(){ return "specialite";}
		 public function get_name_code_universite(){ return "code_universite";}
		 public function get_name_code_etablissement(){ return "code_etablissement";}
		 public function get_name_login(){ return "login";}
		 public function get_name_motpasse(){ return "motpasse";}
		 public function set_cin($parametre){  $this->_cin=$parametre;}	
		 public function set_nom_enseig($parametre){  $this->_nom_enseig=$parametre;}	
		 public function set_prenom_enseig($parametre){  $this->_prenom_enseig=$parametre;}	
		 public function set_tel_mobile($parametre){  $this->_tel_mobile=$parametre;}	
		 public function set_tel($parametre){  $this->_tel=$parametre;}	
		 public function set_fax($parametre){  $this->_fax=$parametre;}	
		 public function set_mail($parametre){  $this->_mail=$parametre;}	
		 public function set_grade($parametre){  $this->_grade=$parametre;}	
		 public function set_specialite($parametre){  $this->_specialite=$parametre;}	
		 public function set_code_universite($parametre){  $this->_code_universite=$parametre;}	
		 public function set_code_etablissement($parametre){  $this->_code_etablissement=$parametre;}	
		 public function set_login($parametre){  $this->_login=$parametre;}	
		 public function set_motpasse($parametre){  $this->_motpasse=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_cin(){ return $this->_cin;}
		 public function get_nom_enseig(){ return $this->_nom_enseig;}
		 public function get_prenom_enseig(){ return $this->_prenom_enseig;}
		 public function get_tel_mobile(){ return $this->_tel_mobile;}
		 public function get_tel(){ return $this->_tel;}
		 public function get_fax(){ return $this->_fax;}
		 public function get_mail(){ return $this->_mail;}
		 public function get_grade(){ return $this->_grade;}
		 public function get_specialite(){ return $this->_specialite;}
		 public function get_code_universite(){ return $this->_code_universite;}
		 public function get_code_etablissement(){ return $this->_code_etablissement;}
		 public function get_login(){ return $this->_login;}
		 public function get_motpasse(){ return $this->_motpasse;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT_ENS()
{

$sql=" INSERT INTO 
 enseignant(
			cin,
			nom_enseig,
			prenom_enseig,
			tel_mobile,
			tel,
			fax,
			mail,
			grade,
			specialite,
			code_universite,
			code_etablissement,
			login,
			motpasse)
 VALUES(
			'".$this->_cin."',
			'".$this->_nom_enseig."',
			'".$this->_prenom_enseig."',
			'".$this->_tel_mobile."',
			'".$this->_tel."',
			'".$this->_fax."',
			'".$this->_mail."',
			'".$this->_grade."',
			'".$this->_specialite."',
			'".$this->_code_universite."',
			'".$this->_code_etablissement."',
			'".$this->_login."',
			'".$this->_motpasse."')";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE_ENS()
{

 $sql="";
if(!empty($this->_cin)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
cin='".$this->_cin."'";
}
if(!empty($this->_nom_enseig)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
nom_enseig='".$this->_nom_enseig."'";
}
if(!empty($this->_prenom_enseig)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
prenom_enseig='".$this->_prenom_enseig."'";
}
if(!empty($this->_tel_mobile)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
tel_mobile='".$this->_tel_mobile."'";
}
if(!empty($this->_tel)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
tel='".$this->_tel."'";
}
if(!empty($this->_fax)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
fax='".$this->_fax."'";
}
if(!empty($this->_mail)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
mail='".$this->_mail."'";
}
if(!empty($this->_grade)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
grade='".$this->_grade."'";
}
if(!empty($this->_specialite)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
specialite='".$this->_specialite."'";
}
if(!empty($this->_code_universite)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
code_universite='".$this->_code_universite."'";
}
if(!empty($this->_code_etablissement)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
code_etablissement='".$this->_code_etablissement."'";
}
if(!empty($this->_login)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
login='".$this->_login."'";
}
if(!empty($this->_motpasse)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
motpasse='".$this->_motpasse."'";
}
$sql="UPDATE 
enseignant SET 
 ".$sql."
								WHERE cin ='".$this->_cin."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE_ENS(){

 $sql="DELETE FROM 
enseignant 
 
									WHERE cin ='".$this->_cin."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
enseignant ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		cin,
		nom_enseig,
		prenom_enseig,
		tel_mobile,
		tel,
		fax,
		mail,
		grade,
		specialite,
		code_universite,
		code_etablissement,
		login,
		motpasse
 FROM 
 enseignant";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_cin=$row->cin;
		$this->_nom_enseig=$row->nom_enseig;
		$this->_prenom_enseig=$row->prenom_enseig;
		$this->_tel_mobile=$row->tel_mobile;
		$this->_tel=$row->tel;
		$this->_fax=$row->fax;
		$this->_mail=$row->mail;
		$this->_grade=$row->grade;
		$this->_specialite=$row->specialite;
		$this->_code_universite=$row->code_universite;
		$this->_code_etablissement=$row->code_etablissement;
		$this->_login=$row->login;
		$this->_motpasse=$row->motpasse;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>